/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucmconfchecker.pucm2graph;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import ucmconfchecker.conformance.ConformanceChecker;
import ucmconfchecker.conformance.Event;
import ucmconfchecker.conformance.EventTrace;
import ucmconfchecker.conformance.SimpleEventTrace;
import ucmconfchecker.pActivationTrace.ArchEvent;
import ucmconfchecker.pActivationTrace.ResponsibilityActivationTrace;

/**
 *
 * @author Administrador
 */
public class ExcecutionTrace2Events<T> {
    
    public EventTrace<T> asEvents(ResponsibilityActivationTrace activationTrace,String name){
        if(activationTrace==null)
            return null;
        Date start = new Date();
        Date finish = new Date();
        for(ArchEvent archEvent: activationTrace){
            Date eventStart = archEvent.getBegin();
            if(start.compareTo(eventStart)>0){
                start = eventStart;
            }
            Date eventFinish = archEvent.getEnd();
            if(finish.compareTo(eventFinish)<0){
                finish = eventFinish;
            }
        }
        SimpleEventTrace<T> result = new SimpleEventTrace<T>(name);
        result.setTimeStart(start);
        result.setTimeFinish(finish);
        Long startL = start.getTime();
        for(ArchEvent archEvent: activationTrace){
            Event<T> event = new Event<T>(start,(archEvent.getBegin().getTime()-startL),
                                         (archEvent.getEnd().getTime()-startL),
                                          (T)archEvent.getResponsibility());
            event.addTrace(archEvent.getRespTrace());
            result.add(event);
//            ConformanceChecker.gantt(event,250);
        }
        return result;
    }
}
